﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using DevExpress.XtraBars;
using System.Collections.ObjectModel;
using YidanSoft.FrameWork.Plugin.Manager;
using YidanSoft.FrameWork.WinForm;
using YidanSoft.FrameWork;

#endregion

namespace YidanSoft.MainFrame
{
    internal class PluginTopMenuItem: BarSubItem,IPlugInMenuInfo
    {
        Collection<IPlugInMenuInfo> _subitems = new Collection<IPlugInMenuInfo>();

         /// <summary>
        /// 创建顶层项,没有Plugin信息
        /// </summary>
        /// <param name="caption"></param>
        public PluginTopMenuItem(string caption):base()
        {
            Name = caption;
            Caption = caption;
            this.ItemLinks.CollectionChanged += new System.ComponentModel.CollectionChangeEventHandler(ItemLinks_CollectionChanged);
        }

        void ItemLinks_CollectionChanged(object sender, System.ComponentModel.CollectionChangeEventArgs e)
        {
            _subitems.Clear();
            for (int i = 0; i < ItemLinks.Count; i++)
            {
                IPlugInMenuInfo pmi = ItemLinks[i].Item as IPlugInMenuInfo;
                if (pmi != null) _subitems.Add(pmi);
            }
        }

       #region IPlugInMenuInfo Members

        public PlugInConfiguration MenuInfo
        {
            get { return null; }
        }

        public Collection<IPlugInMenuInfo> SubItems
        {
            get
            {
                return _subitems;
            }
        }

        public string Text
        {
            get { return Caption; }
            set { Caption = value; }
        }

        #endregion

        public override string ToString()
        {
            return Caption;
        }
    }

    internal class PluginMenuItem : BarButtonItem, IPlugInMenuInfo
    {
        PlugInConfiguration _plugincfg;

        /// <summary>
        /// Ctor2
        /// </summary>
        /// <param name="plugin"></param>
        public PluginMenuItem(PlugInConfiguration plugincfg):base()
        {
            _plugincfg = plugincfg;
            Caption = plugincfg.MenuCaption;
            Name = plugincfg.AssemblyName + ":" + plugincfg.AssemblyStartupClass;
        }

        public PluginMenuItem(IPlugIn plugin)
        {
            _plugincfg = new PlugInConfiguration();
            _plugincfg.AssemblyName = plugin.AssemblyFileName;
            _plugincfg.AssemblyStartupClass = plugin.StartClassType;
            Name = _plugincfg.AssemblyName + ":" + _plugincfg.AssemblyStartupClass;
        }

        public PluginMenuItem(string caption)
        {
            Caption = caption;
        }

        public PlugInConfiguration MenuInfo
        {
            get { return _plugincfg; }
        }

        public Collection<IPlugInMenuInfo> SubItems
        {
            get{ return null;}
        }

        public string Text
        {
            get { return Caption; }
            set { Caption = value; }
        }

        public override string ToString()
        {
            return Caption;
        }
    }
}
